import api from '../../utils/api';

Page({
  data: {
    page: 1,
    classifyData: [],
    loading: true
  },
  onLoad() {},
  onShow() {
    // 页面显示
    console.log('页面显示');
    this.getList({page: 1});
  },
  // 获取分类列表
  async getList (params) {
    const data = await api.getCategories(params);
    if (data && Array.isArray(data)) {      
      this.setData({
        classifyData: data,
        loading: false
      })
    }
  },
  // 点击分类跳转到文章列表
  bindColumn (e) {
    const name = e.currentTarget.dataset.name;
    const id = e.currentTarget.id;
    my.navigateTo({
      url: `/pages/list/list?id=${id}&name=${name}`
    })
  }
});
